package com.cumulus.ianerp.ian.auth.emp.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cumulus.ianerp.ian.auth.emp.domain.Emp;
import com.cumulus.ianerp.ian.auth.emp.service.EmpService;
/**
 * 用户的控制层
 * @author Ian
 * @date 2017-05-13
 *
 */

@Controller
public class EmpAction {
	@Autowired
	private EmpService empService;
	
	/**
	 * 用户登录
	 * @author Ian
	 * @date 2017-05-13
	 * 
	 */
	@RequestMapping("/userLogin.action")
	public String userLogin(Emp emp,String verifyCode,HttpSession session,Model model){
		boolean isExists=empService.empLogin(emp, session);
		String verify = (String) session.getAttribute("verify");
		if(!verifyCode.equalsIgnoreCase(verify)){
			model.addAttribute("verifyError", "验证码不正确");
			return "/login.jsp";
		}
		if(isExists){
				return "redirect:/findTheMenu.action";
		}
		
		model.addAttribute("loginError", "用户名不存在或密码错误");
		return "/login.jsp";
	}

}
